package com.sanlit.inv;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

/**
 * @author junjie.li
 * @date 2021/3/21 14:50
 */
public class CodeGenerator {

    public static void main(String[] args)

    {
        AutoGenerator mpg = new AutoGenerator();
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setSwagger2(true);
        mpg.setGlobalConfig(globalConfig);

        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/inv?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("root");
        mpg.setDataSource(dsc);

        mpg.setPackageInfo(new PackageConfig().setParent("com.sanlit").setModuleName("inv"));
        mpg.getGlobalConfig()
                .setOpen(false)
                .setAuthor("junjie.li@aliyun.com")
                .setOutputDir("D:\\YouLuWork\\framework\\examples\\code-gen\\src\\main\\java");


        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();
        mpg.setTemplate(templateConfig);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        strategy.setControllerMappingHyphenStyle(true);
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());

        mpg.execute();
    }
}
